///*
// * To change this template, choose Tools | Templates
// * and open the template in the editor.
// */
//package br.com.foxline.manager.search;
//
//import br.com.foxline.enums.Status;
//import br.com.foxline.enums.TypeAnnex;
//import br.com.foxline.enums.TypeDocument;
//import br.com.foxline.enums.TypeQuality;
//import br.com.foxline.enums.TypeRequirement;
//import br.com.foxline.model.Address;
//import br.com.foxline.model.Annex;
//import br.com.foxline.model.People;
//import br.com.foxline.model.Requirement;
//import br.com.foxline.service.*;
//import br.com.foxline.util.Caracter;
//import br.com.foxline.util.Msg;
//import java.io.IOException;
//import java.io.InputStream;
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.List;
//import java.util.Map;
//import javax.annotation.PostConstruct;
//import javax.ejb.EJB;
//import javax.faces.bean.ManagedBean;
//import javax.faces.bean.ViewScoped;
//import javax.faces.context.FacesContext;
//import javax.faces.model.SelectItem;
//import org.primefaces.event.FileUploadEvent;
//
///**
// *
// * @author ely
// */
//@ManagedBean
//@ViewScoped
//public class ManagerSearchRequirement {
//
//    @EJB
//    RequirementService reqService;
//    @EJB
//    AnnexService annexService;
//    @EJB
//    PhysicalService physicalService;
//    @EJB
//    CompanyService companyService;
//    @EJB
//    PeopleService peopleService;
//    @EJB
//    AddressService addressService;
//    
//    private boolean readOnlyInputs;
//    private Requirement searchReq;
//    private List<Requirement> searchreqs;
//    private List<Requirement> searchDispatchReqs;
//    private Requirement editReq;
//    private Requirement showReq;
//    private Requirement foDispatchReq;
//    private Requirement searchDispatchReq;
//    private People interested;
//    private boolean disableAnnexButton;
//    private Annex annex;
//    private List<Annex> annexs;
//    private Annex a;
//    private String reqEdit;
//    private String reqShow;
//    private String fDispatch;
//    private People searchPeople;
//    private People searchPeopleDispatch;
//    
//    @PostConstruct
//    public void init() {
//        searchReq = new Requirement();
//        searchPeople = new People();
//        searchPeople.setTypeDocument(TypeDocument.CPF);
//        searchDispatchReq = new Requirement();
//        searchPeopleDispatch = new People();
//        searchPeopleDispatch.setTypeDocument(TypeDocument.CPF);
//        
//        annex = new Annex();
//        disableAnnexButton = true;
//
//        a = new Annex();
//
//
//
//        Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
//        reqEdit = params.get("reqEdit");
//        reqShow = params.get("reqShow");
//        fDispatch = params.get("fDispatch");
//        paramPost();
//    }
//
//    public List<SelectItem> getTypeRequeriment() {
//        List<SelectItem> r = new ArrayList<SelectItem>();
//        for (TypeRequirement ms : TypeRequirement.values()) {
//            r.add(new SelectItem(ms, ms.getName()));
//        }
//        return r;
//    }
//
//    public List<SelectItem> getStatus() {
//        List<SelectItem> s = new ArrayList<SelectItem>();
//        for (Status ms : Status.values()) {
//            s.add(new SelectItem(ms, ms.getName()));
//        }
//        return s;
//    }
//
//    public List<SelectItem> getTypeAnnex() {
//        List<SelectItem> t = new ArrayList<SelectItem>();
//        for (TypeAnnex ta : TypeAnnex.values()) {
//            t.add(new SelectItem(ta, ta.getName()));
//        }
//        return t;
//    }
//    
//     public List<SelectItem> getTypeQuality() {
//
//        List<SelectItem> t = new ArrayList<SelectItem>();
//        for (TypeQuality ta : TypeQuality.values()) {
//            t.add(new SelectItem(ta, ta.getName()));
//        }
//        return t;
//    }
//
//
//    public void ajaxTypeAnnex() {
//        annexService.ajaxTypeAnnex(annex, a);
//        if (annex.getType_annex() != null) {
//            disableAnnexButton = false;
//        } else {
//            disableAnnexButton = true;
//        }
//    }
//
//    public void removeAnnex(int a) {
//        try {
//            annexs.remove(a);
//            Msg.messagemInfo("Documento Excluído");
//        } catch (Exception erro) {
//            erro.printStackTrace();
//        }
//    }
//
//    public void existInterested() {
//        peopleService.removeCaracterDocument(interested);
//        if (interested.getTypeDocument() == TypeDocument.CPF) {
//            if (interested.getCpf().equals("")) {
//                interested = new People();
//                interested.setTypeDocument(TypeDocument.CPF);
//            } else {
//                interested = reqService.existDocuments(interested);
//            }
//            readOnlyInputs = interested.getId() != null;
//        } else if (interested.getTypeDocument() == TypeDocument.CNPJ) {
//            if (interested.getCnpj().equals("")) {
//                interested = new People();
//                interested.setTypeDocument(TypeDocument.CNPJ);
//            } else {
//                interested = reqService.existDocuments(interested);
//            }
//            readOnlyInputs = interested.getId() != null;
//        }
//    }
//
//    public void updateRequeriment() {
//
//        if (interested.getId() == null) {
//            interested.setName(interested.getName());
//            peopleService.removeCaracterDocument(interested);
//            Address addres = new Address();
//            interested.setAddress(addres);
//            addressService.save(interested.getAddress());
//            peopleService.save(interested);
//            editReq.setOwner(interested);
//            reqService.updateRequirement(editReq, annexs);
//           
//        } else {
//            editReq.setOwner(interested);
//            reqService.updateRequirement(editReq, annexs);
//        }
//    }
//
//    public void handle(FileUploadEvent event) throws IOException {
//        handleAux(event.getFile().getContents(), event.getFile().getFileName(),
//                event.getFile().getContentType(), event.getFile().getInputstream());
//    }
//
//    private void handleAux(byte[] imageBytes, String nome, String tipo, InputStream is) throws IOException {
//
//        byte[] bytes = null;
//        annex = new Annex();
//        bytes = imageBytes;
//        annex.setType(tipo);
//        annex.setDescription(nome);
//
//        if (bytes != null) {
//            annex.setFileByte(bytes);
//            annex.setType_annex(a.getType_annex());
//            annexService.save(annex);
//
//            annexs.add(annex);
//            System.out.println(annex);
//
//            annex = new Annex();
//
//            Msg.messagemInfo("Anexado com Sucesso");
//        }
//    }
//
//    public void paramPost() {
//        try {
//            if (reqShow != null) {
//                showReq = reqService.find(Long.parseLong(reqShow));
//                annexs = reqService.findAnnex(showReq);
//                interested = showReq.getOwner();
//            } else if (reqEdit != null) {
//                editReq = reqService.find(Long.parseLong(reqEdit));
//                annexs = reqService.findAnnex(editReq);
//                interested = editReq.getOwner();
//            } else if (fDispatch != null) {
//                foDispatchReq = reqService.find(Long.parseLong(fDispatch));
//                annexs = reqService.findAnnex(foDispatchReq);
//                interested = foDispatchReq.getOwner();
//            }    
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//
//    public List<SelectItem> typeDocumentList() {
//        List<SelectItem> items = new ArrayList<SelectItem>();
//        for (TypeDocument tipo : TypeDocument.values()) {
//            if (tipo != TypeDocument.OAB) {
//                items.add(new SelectItem(tipo.getType(), tipo.getName()));
//            }
//        }
//        return items;
//    }
//
//    public void searchRequirement() {
//        searchPeople.setCnpj(Caracter.removecaracter(searchPeople.getCnpj()));
//        searchPeople.setCpf(Caracter.removecaracter(searchPeople.getCpf()));
//        searchreqs = reqService.findRequirement(searchReq, searchPeople);
//    }
//    
//    public void searchFDispatch(){
//        searchPeopleDispatch.setCnpj(Caracter.removecaracter(searchPeopleDispatch.getCnpj()));
//        searchPeopleDispatch.setCpf(Caracter.removecaracter(searchPeopleDispatch.getCpf()));
//        searchDispatchReqs = reqService.findDispatchReq(searchDispatchReq, searchPeopleDispatch);
//    }
//    
//    public void updateDispatch(){
//        try{
//            foDispatchReq.setCreate_at_dispatch(new Date());
//            foDispatchReq.setStatus(Status.PROTOCOLO);
//            reqService.update(foDispatchReq);
//            Msg.messagemInfo("Operação Realizado com Sucesso ");
//        }catch(Exception erro){
//            
//        }
//    }
//    
//    public void updateProtocol(){
//        try{
//            foDispatchReq.setCreate_at_protocol(new Date());
//            foDispatchReq.setStatus(Status.PROTOCOLO);
//            reqService.update(foDispatchReq);
//            Msg.messagemInfo("Operação Realizado com Sucesso ");
//        }catch(Exception erro){
//            
//        }
//    }
//
//    public Requirement getSearchReq() {
//        return searchReq;
//    }
//
//    public void setSearchRequirement(Requirement searchReq) {
//        this.searchReq = searchReq;
//    }
//
//    public List<Requirement> getSearchreqs() {
//        return searchreqs;
//    }
//
//    public void setSearchreqs(List<Requirement> searchreqs) {
//        this.searchreqs = searchreqs;
//    }
//
//    public Requirement getEditReq() {
//        return editReq;
//    }
//
//    public void setEditReq(Requirement editReq) {
//        this.editReq = editReq;
//    }
//
//    public Annex getAnnex() {
//        return annex;
//    }
//
//    public void setAnnex(Annex annex) {
//        this.annex = annex;
//    }
//
//    public List<Annex> getAnnexs() {
//        return annexs;
//    }
//
//    public void setAnnexs(List<Annex> annexs) {
//        this.annexs = annexs;
//    }
//
//    public Requirement getShowReq() {
//        return showReq;
//    }
//
//    public void setShowReq(Requirement showReq) {
//        this.showReq = showReq;
//    }
//
//    public boolean isDisableAnnexButton() {
//        return disableAnnexButton;
//    }
//
//    public void setDisableAnnexButton(boolean disableAnnexbutton) {
//        this.disableAnnexButton = disableAnnexbutton;
//    }
//
//    public People getSearchPeople() {
//        return searchPeople;
//    }
//
//    public void setSearchPeople(People searchPeople) {
//        this.searchPeople = searchPeople;
//    }
//
//    public boolean isReadOnlyInputs() {
//        return readOnlyInputs;
//    }
//
//    public void setReadOnlyInputs(boolean readOnlyInputs) {
//        this.readOnlyInputs = readOnlyInputs;
//    }
//
//    public People getInterested() {
//        return interested;
//    }
//
//    public void setInterested(People interested) {
//        this.interested = interested;
//    }
//
//    public List<Requirement> getSearchDispatchReqs() {
//        return searchDispatchReqs;
//    }
//
//    public void setSearchDispatchReqs(List<Requirement> searchDispatchReqs) {
//        this.searchDispatchReqs = searchDispatchReqs;
//    }
//
//    public Requirement getFoDispatchReq() {
//        return foDispatchReq;
//    }
//
//    public void setFoDispatchReq(Requirement foDispatchReq) {
//        this.foDispatchReq = foDispatchReq;
//    }
//
//    
//
//    public Requirement getSearchDispatchReq() {
//        return searchDispatchReq;
//    }
//
//    public void setSearchDispatchReq(Requirement searchDispatchReq) {
//        this.searchDispatchReq = searchDispatchReq;
//    }
//
//   
//
//    public People getSearchPeopleDispatch() {
//        return searchPeopleDispatch;
//    }
//
//    public void setSearchPeopleDispatch(People searchPeopleDispatch) {
//        this.searchPeopleDispatch = searchPeopleDispatch;
//    }
//     
//}
